package core.model;

public class ImapServerMail implements Comparable<ImapServerMail>{

	private int     index;
	private String  name;
	private String  domain;
	private String  host;
	private int     port;
	private boolean useDomain;
	private boolean tlsRequired;
	
	public ImapServerMail() {
	}

	public ImapServerMail(int index, String name, String host, int port) {
		this.index = index;
		this.name = name;
		this.host = host;
		this.port = port;
	}
	
	public ImapServerMail(int index, String name,String host, int port,String domain) {
		this.index = index;
		this.name = name;
		this.domain = domain;
		this.host = host;
		this.port = port;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public String getDomain() {
		return domain;
	}
	
	public void setDomain(String domain) {
		this.domain = domain;
	}
	
	public ImapServerMail domain(){
		this.useDomain = true;
		return this;
	}
	
	public ImapServerMail tlsSsl(){
		this.tlsRequired = true;
		return this;
	}
	
	public boolean isUseDomain() {
		return useDomain;
	}
	
	public boolean isTlsRequired() {
		return tlsRequired;
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((host == null) ? 0 : host.hashCode());
		result = prime * result + index;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + port;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ImapServerMail other = (ImapServerMail) obj;
		if (host == null) {
			if (other.host != null)
				return false;
		} else if (!host.equals(other.host))
			return false;
		if (index != other.index)
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (port != other.port)
			return false;
		return true;
	}

	@Override
	public int compareTo(ImapServerMail o) {
		return index - o.index;
	}
	
}
